const socket = new WebSocket(
  'wss://javascript.info/article/websocket/demo/hello'
)

socket.onopen = function () {
  console.log('链接打开了')
  socket.send('向服务器推送：张啤酒，早上好')
}

socket.onmessage = (evt) => {
  console.log('收到服务器主动推送过来的消息：', evt)
  socket.close() // 客户端主动关闭
}

socket.onclose = () => {
  console.log('断开连接')
}
